package com.example.myapplication.ui.Home.fragments;


import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.StaggeredGridLayoutManager;
import android.view.View;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.example.myapplication.R;
import com.example.myapplication.base.BaseMvpFragment;
import com.example.myapplication.model.bean.PhotoGirl;
import com.example.myapplication.presenter.GrilPresenter;
import com.example.myapplication.presenter.contract.GrilContract;
import com.example.myapplication.ui.Home.adapter.CommonRecycleViewAdapter;
import com.example.myapplication.ui.news.activity.GrilActivity;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;

public class GrilFragment extends BaseMvpFragment<GrilPresenter> implements GrilContract.View, BaseQuickAdapter.OnRecyclerViewItemClickListener {
    CommonRecycleViewAdapter adapter;


    @BindView(R.id.base_title_text)
    TextView TitleText;
    @BindView(R.id.rc_view)
    RecyclerView RcView;
    private static int SIZE = 20;
    private int mStartPage = 1;
    @Override
    protected GrilPresenter initPresenter() {
        return new GrilPresenter(getActivity());
    }
    @Override
    protected int getLayoutId() {
        return R.layout.fragment_gril;
    }

    @Override
    protected void initView() {
        TitleText.setText(getString(R.string.girl_title));
        adapter=new CommonRecycleViewAdapter(R.layout.item_photo,new ArrayList<>());
        RcView.setLayoutManager(new StaggeredGridLayoutManager(2,StaggeredGridLayoutManager.VERTICAL));
        RcView.setAdapter(adapter);
        adapter.setOnRecyclerViewItemClickListener(this);
    }

    @Override
    protected void initEventAndData() {
        mPresenter.requestSplashData(SIZE,mStartPage);
    }


    @Override
    public void showError(String msg) {

    }


    @Override
    public void scouss(List<PhotoGirl> photoGirls) {
        adapter.addData(photoGirls);
    }

    @Override
    public void onItemClick(View view, int i) {
        GrilActivity.startAction(getActivity(),adapter.getData().get(i).getUrl());
    }
}
